<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>后台管理-消息管理</title>
		<link rel="stylesheet" href="/resources/src/css/lib/bootstrap.min.css">
		<link rel="stylesheet" href="/resources/src/css/admin/main.css" />
		<link rel="stylesheet" href="/resources/src/css/admin/user-manage.css" />
    </head>
    <body>
		<article class="main">
			<div class="main-wrapper">
				<section class="content">
				<form id="myForm" action="/admin/message/list">
					<div class="container">
						<div class="con-body">
							<div class="toolbar clearfix">
								<div class="toolbar-left pull-left">
									<a href="/admin/message/addMessage" id="create" class="pull-left">新建</a>
									<!-- <a href="#" id="delete" class="pull-right">删除</a> -->
								</div>
								<!-- <div class="toolbar-right pull-right">
									<div class="input-icon">
										<input type="text" id="condition" placeholder="输入用户名/手机/邮箱查询"/>
										<i class="iconfont icon-sousuo" id="searchMessage"></i>
									</div>
								</div> -->
							</div>
							<div class="user-table table-responsive">
								<table class="table">
									<thead>
										<tr>
											<th>标题</th>
											<th>内容</th>
											<th>发送者</th>
											<th>接收对象</th>
											<th>发送时间</th>
											<th data-toggle="joDropdown">
												发送状态<i class="iconfont icon-caidanshaixuan"></i>
												<ul data-toggle="joMenu">
													<li><a href="javascript:void(0);" onclick="selectStatus(0);">全部</a></li>
													<li><a href="javascript:void(0);" onclick="selectStatus(1);">成功</a></li>
													<li><a href="javascript:void(0);" onclick="selectStatus(2);">失败</a></li>
												</ul>
											</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="mytable">
										<c:forEach items="${page.result }" var="message">
											<tr data-userId="255">
												<td><a href="/admin/message/detail/${message.id }">${message.title }</a></td>
												<td>${message.content }</td>
												<td>${message.sendUser.userName }</td>
												<td>${message.receiveUser.userName }</td>
												<td>${message.createTime }</td>
												<td>${message.status == 1 ?'成功':'失败' }</td>
												<td><a data-btn="delMessage" onclick="deleteMessage(${message.id})">删除</a></td>
											</tr>
										</c:forEach>
										<tr>
										<td colspan="7"  style="border:0"><jsp:include page="/common/adminPage.jsp" /></td>
										</tr>
									</tbody>
								</table>		
							</div>
						</div>
					</div>
					</form>
				</section>
			</div>
		</article>
		
		<!-- 提示模态框 -->
		<div class="joModal" id="message-modal" data-liffect="fadeIn">
			<div class="joModal-dialog">
				<div class="joModal-content" data-liffect="slideTop">
					<div class="joModal-body">
						<p class="text-tip">是否要删除选中的消息，删除后不可恢复？</p>
					</div>
					<input type="hidden" id="messageId" value=""/>
					<div class="joModal-footer clearfix">
						<a class="pull-left cancel modal-btn" data-modal="close" >取消</a>
						<a class="pull-left confirm modal-btn">确定</a>
					</div>
				</div>
			</div>	
		</div>
		
		<script src="/resources/src/js/jquery-2.1.4.js"></script>
		<script src="/resources/src/js/jquery.nicescroll.js"></script>
		<script src="/resources/src/js/admin/main.js"></script>
		<script src="/resources/src/js/adminPage.js"></script>
		<script>
			$(function(){
				//搜索
			 	$("#search-btn").on("click",function(){
			 		var value=$("#search").val().trim();
			 		if(value!="" && value!=null){
			 			console.log(value);
			 			/*
			 			$.ajax({
			 				type:"get",
			 				url:"",
			 				async:true,
			 				data:"",
			 				success:function(data){
			 					//do something
			 				}
			 			});*/
			 		}
			 	});
			 	
			 	//删除消息
			 	userTable.delUser("#message-modal .confirm",function(data){
			 		//参数data为表格行的id(data-userId)的值
			 		console.log(data);
			 		var messageId = $("#messageId").val();
		 			$.ajax({
		 				type:"post",
		 				url:"/admin/message/delete",
		 				async:true,
		 				data:{"id":messageId},
		 				dataType:'json',
		 				success:function(data){
					 		Global.modal("#message-modal","hide");
		 					alert(data.data);
		 					location.reload();
		 				}
		 			});
			 	});
			 	
			 	
				/* $("#delConfirm").on("click",function(){
					var messageId = $("#messageId").val();
			 			$.ajax({
			 				type:"post",
			 				url:"/admin/message/delete",
			 				async:true,
			 				data:{"id":messageId},
			 				dataType:'json',
			 				success:function(data){
			 					alert(data.data);
			 					location.reload();
			 				}
			 			});
			 	}); */
			});
			
			//删除前
		 	function deleteMessage(messageId){
		 		$("#messageId").val(messageId);
		 	}
			
			function selectStatus(status) {
				$.ajax({
	 				type:"post",
	 				url:"/admin/message/list",
	 				async:true,
	 				data:{"status":status},
	 				success:function(data){
	 					$("#mytable").html(data);
	 				}
	 			});
			}
		</script>
		
 	</body>
</html>